package com.golddaymicromall.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;


/**
 * Created by dawd on 2016/2/17.
 */
/*
 *网络判断工具类
 * */
public class IsNetUtils {
    private Context ctx;

    public IsNetUtils(Context ctx){
        this.ctx = ctx;
    }

    public boolean IsNet(){
        boolean flag = false;
        ConnectivityManager manager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info;
        NetworkInfo.State state;
        info = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if(info!= null){
            state = info.getState();
            if(state == NetworkInfo.State.CONNECTED){
                flag = true;
                return flag;
            }
        }
        info = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if(info!= null){
            state = info.getState();
            if(state == NetworkInfo.State.CONNECTED){
                flag = true;
                return flag;
            }
        }
        return flag;
    }
}
